<template>
  <!-- 利息管理   -->
    <div class="interestCalculationDetailsPage">
        <div class="search-wrap d-flex a-center">

            <div class="search-item d-flex a-center m-l20">
                <label>贷款银行</label>
                <el-select class="m-l10" v-model="form.bankAccountId" clearable>
                    <el-option v-for="(item,index) in bankAccountList" :key="index" :label="item.bankName" :value="item.bankAccountId"></el-option>
                </el-select>
            </div>
            <div class="search-buttons m-l50 d-flex a-center">
                <el-button
                        color="#fc702b"
                        style="color:#fff;"
                        @click.prevent="onQuery"
                >查询</el-button>
                <el-button
                        color="#f0f0f0"
                        style="color: #000000"
                        @click.prevent="onReset"
                >重置</el-button>
                <el-divider direction="vertical" />
                <el-button
                        @click.prevent="deleteInterest"
                        class="button_delete m-r10"
                >删除</el-button>
                <el-button
                        class="button_edit"
                        @click="onExport"
                >
                    <svg-icon icon-class="project-detail-icon-derive" class="icon-export m-r5"></svg-icon>
                    一键导出
                </el-button>
            </div>
        </div>
        <public-table
                ref="publicTableRef"
                class="m-t20"
                index
                selection
                :page="page"
                :tableData="tableData"
                :tableOption.sync="tableOption"
                @page-change="onPageChange"
                @handle-selection-change="handleSelectionChange"
        ></public-table>
    </div>
</template>

<script setup>
import {onMounted, reactive, ref} from "vue";
import {
    ElSelect,
    ElOption,
    ElDivider, ElMessage, ElMessageBox,
} from "element-plus";
import PublicTable from "@/components/PublicTable.vue";

import {tableCommonFun} from "@/hooks/tableCommon";
import {companyApi, interestManagement} from "@/api/businessFinance";

const interfaceConfig = reactive({
    fileName:'businessFinance',
    apiPath:'interestManagement.getPageList',
});
const exportConfig = reactive({
    fileName:'businessFinance',
    apiPath:'exportApi.getPageListLeadingOut',
    tableName:'利息管理表'
});
const {
    form,
    page,
    tableOption,
    tableData,
    selectedArr,
    onQuery,
    onReset,
    onPageChange,
    getData,
    onExport,
    handleSelectionChange
}  = tableCommonFun(interfaceConfig,exportConfig);

form.value = {
    bankAccountId:'',
    companyId:''
}

tableOption.value = [
  { label: "贷款银行 ", prop: "bankName", minWidth: 100 },
  { label: "利息调整日期", prop: "interestRateUpdateTime", minWidth: 120 },
  { label: "调整日利率", prop: "lastInterestRate", minWidth: 100 },
  { label: "最新利率", prop: "currentInterestRate", minWidth: 100 },
  { label: "提取时间", prop: "drawTime", minWidth: 100 },
  { label: "计提开始时间", prop: "startTime", minWidth: 120 },
  { label: "计提结束时间", prop: "endTime", minWidth: 120 },
  { label: "计提应付金额", prop: "interestAmount", minWidth: 120 },
];

/**
 * 查询银行列表
 *
 */
const bankAccountList = ref([]);
const getBankList = () => {
    companyApi.getBankList().then(res=>{
        if(res.code === '200'){
            bankAccountList.value = res.data;
        }
    });
}

/**
 * 删除计提按钮
 */
const deleteInterest = () => {
  if (selectedArr.value.length === 0) {
    ElMessage.warning('请选择要删除的行!');
    return;
  }
  ElMessageBox.alert(`已选择${selectedArr.value.length}条数据，是否删除？`, '提示', {
    confirmButtonText: '确认',
    confirmButtonClass: "button_view",
    callback: (action) => {
      if (action === 'confirm') {
        interestManagement.deleteBankLoanInterest({
          list: selectedArr.value.map(item => { return item.loanInterestId })
        }).then(res => {
          ElMessage.success('删除成功!');
          page.current = 1;
          page.size = 10;
          getData({
            pageNum: 1,
            pageSize: 10
          });
        });
      }
    },
  })
};

onMounted(()=>{
    getData({
        pageNum:1,
        pageSize:10
    });
    getBankList();
});
</script>

<style lang="scss" scoped>
.interestCalculationDetailsPage{
  .search-wrap{
    .search-item{

      .el-input{
        width: auto !important;
      }
    }
    .search-buttons{
      .icon-export{
        width: 18px;
        height: 18px;
      }
    }
  }
}
.public-dialog-content{
  .dialog-title-box{
    height: 30px;
    span{
      font-size: 15px;
      font-weight: 600;
    }
  }
}
</style>
